package com.zjb.chuangxiang.fabu;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class FaBuActivity extends AppCompatActivity {

    private ImageView mImageView4;
    private View mRela1;
    private View mRela2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view);
        RelativeLayout relaBg = (RelativeLayout) findViewById(R.id.relaBg);
        mImageView4 = (ImageView) findViewById(R.id.imageView4);
        mRela1 = findViewById(R.id.rela1);
        mRela2 = findViewById(R.id.rela2);
//        Animation animation2 = AnimationUtils.loadAnimation(this, R.anim.xuanzhuan);
//        animation2.setFillAfter(true);
//        if (animation2 != null) {
//            imageView4.startAnimation(animation2);
//        }
        mImageView4.animate().rotation(360);
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.wangshanghuitan);
        animation.setFillAfter(true);
        if (animation != null) {
            mRela1.startAnimation(animation);
        }
        Animation animation1 = AnimationUtils.loadAnimation(this, R.anim.wangshanghuitan);
        animation1.setFillAfter(true);
        animation1.setStartOffset(200);
        if (animation != null) {
            mRela2.startAnimation(animation1);
        }
    }

    @Override
    public void onBackPressed() {
        Animation animation2 = AnimationUtils.loadAnimation(this, R.anim.xuanzhuan_ni);
        animation2.setFillAfter(true);
        if (animation2 != null) {
            mImageView4.startAnimation(animation2);
        }
        animation2.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                finish();
                overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.wangshanghuitan_ni);
        animation.setFillAfter(true);
        if (animation != null) {
            mRela1.startAnimation(animation);
        }
        Animation animation1 = AnimationUtils.loadAnimation(this, R.anim.wangshanghuitan_ni);
        animation1.setFillAfter(true);
        animation1.setStartOffset(200);
        if (animation != null) {
            mRela2.startAnimation(animation1);
        }
    }
}
